#!/usr/bin/python

import fm,wx,tempfile,shutil,os
from base import *

def safer_save(filename,content):
	fid,tmp=tempfile.mkstemp('__.fm-tmp-savefile',filename+'.__','.')
	os.close(fid) #else it locks the file in Windows, thanks Bill
	#print tmp
	shutil.copy2(filename,tmp)
	fd=open(filename,'w')
	fd.write(content)
	fd.close()
	# if we die anywhere above, at least tmp will remain
	os.remove(tmp)
	
	